package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.MyJob;
import com.xjgzinfo.usdp.repository.MyJobRepository;
import com.xjgzinfo.usdp.service.MyJobService;
import com.xjgzinfo.usdp.service.dto.MyJobDTO;
import com.xjgzinfo.usdp.service.mapper.MyJobMapper;
import com.xjgzinfo.usdp.service.dto.MyJobCriteria;
import com.xjgzinfo.usdp.service.MyJobQueryService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Base64Utils;
import javax.persistence.EntityManager;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link MyJobResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class MyJobResourceIT {

    private static final String DEFAULT_NAME = "AAAAAAAAAA";
    private static final String UPDATED_NAME = "BBBBBBBBBB";

    private static final String DEFAULT_INSTANCE_ID = "AAAAAAAAAA";
    private static final String UPDATED_INSTANCE_ID = "BBBBBBBBBB";

    private static final Integer DEFAULT_STATUS = 1;
    private static final Integer UPDATED_STATUS = 2;
    private static final Integer SMALLER_STATUS = 1 - 1;

    private static final Long DEFAULT_USER_ID = 1L;
    private static final Long UPDATED_USER_ID = 2L;
    private static final Long SMALLER_USER_ID = 1L - 1L;

    private static final Instant DEFAULT_CREATE_TIME = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_CREATE_TIME = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final Instant DEFAULT_UPDATE_TIME = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_UPDATE_TIME = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final String DEFAULT_DESCRIPTION = "AAAAAAAAAA";
    private static final String UPDATED_DESCRIPTION = "BBBBBBBBBB";

    @Autowired
    private MyJobRepository myJobRepository;

    @Autowired
    private MyJobMapper myJobMapper;

    @Autowired
    private MyJobService myJobService;

    @Autowired
    private MyJobQueryService myJobQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restMyJobMockMvc;

    private MyJob myJob;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static MyJob createEntity(EntityManager em) {
        MyJob myJob = new MyJob()
            .name(DEFAULT_NAME)
            .instanceId(DEFAULT_INSTANCE_ID)
            .status(DEFAULT_STATUS)
            .userId(DEFAULT_USER_ID)
            .createTime(DEFAULT_CREATE_TIME)
            .updateTime(DEFAULT_UPDATE_TIME)
            .description(DEFAULT_DESCRIPTION);
        return myJob;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static MyJob createUpdatedEntity(EntityManager em) {
        MyJob myJob = new MyJob()
            .name(UPDATED_NAME)
            .instanceId(UPDATED_INSTANCE_ID)
            .status(UPDATED_STATUS)
            .userId(UPDATED_USER_ID)
            .createTime(UPDATED_CREATE_TIME)
            .updateTime(UPDATED_UPDATE_TIME)
            .description(UPDATED_DESCRIPTION);
        return myJob;
    }

    @BeforeEach
    public void initTest() {
        myJob = createEntity(em);
    }

    @Test
    @Transactional
    public void createMyJob() throws Exception {
        int databaseSizeBeforeCreate = myJobRepository.findAll().size();
        // Create the MyJob
        MyJobDTO myJobDTO = myJobMapper.toDto(myJob);
        restMyJobMockMvc.perform(post("/api/my-jobs").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myJobDTO)))
            .andExpect(status().isCreated());

        // Validate the MyJob in the database
        List<MyJob> myJobList = myJobRepository.findAll();
        assertThat(myJobList).hasSize(databaseSizeBeforeCreate + 1);
        MyJob testMyJob = myJobList.get(myJobList.size() - 1);
        assertThat(testMyJob.getName()).isEqualTo(DEFAULT_NAME);
        assertThat(testMyJob.getInstanceId()).isEqualTo(DEFAULT_INSTANCE_ID);
        assertThat(testMyJob.getStatus()).isEqualTo(DEFAULT_STATUS);
        assertThat(testMyJob.getUserId()).isEqualTo(DEFAULT_USER_ID);
        assertThat(testMyJob.getCreateTime()).isEqualTo(DEFAULT_CREATE_TIME);
        assertThat(testMyJob.getUpdateTime()).isEqualTo(DEFAULT_UPDATE_TIME);
        assertThat(testMyJob.getDescription()).isEqualTo(DEFAULT_DESCRIPTION);
    }

    @Test
    @Transactional
    public void createMyJobWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = myJobRepository.findAll().size();

        // Create the MyJob with an existing ID
        myJob.setId(1L);
        MyJobDTO myJobDTO = myJobMapper.toDto(myJob);

        // An entity with an existing ID cannot be created, so this API call must fail
        restMyJobMockMvc.perform(post("/api/my-jobs").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myJobDTO)))
            .andExpect(status().isBadRequest());

        // Validate the MyJob in the database
        List<MyJob> myJobList = myJobRepository.findAll();
        assertThat(myJobList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkNameIsRequired() throws Exception {
        int databaseSizeBeforeTest = myJobRepository.findAll().size();
        // set the field null
        myJob.setName(null);

        // Create the MyJob, which fails.
        MyJobDTO myJobDTO = myJobMapper.toDto(myJob);


        restMyJobMockMvc.perform(post("/api/my-jobs").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myJobDTO)))
            .andExpect(status().isBadRequest());

        List<MyJob> myJobList = myJobRepository.findAll();
        assertThat(myJobList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkUserIdIsRequired() throws Exception {
        int databaseSizeBeforeTest = myJobRepository.findAll().size();
        // set the field null
        myJob.setUserId(null);

        // Create the MyJob, which fails.
        MyJobDTO myJobDTO = myJobMapper.toDto(myJob);


        restMyJobMockMvc.perform(post("/api/my-jobs").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myJobDTO)))
            .andExpect(status().isBadRequest());

        List<MyJob> myJobList = myJobRepository.findAll();
        assertThat(myJobList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllMyJobs() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList
        restMyJobMockMvc.perform(get("/api/my-jobs?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(myJob.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].instanceId").value(hasItem(DEFAULT_INSTANCE_ID)))
            .andExpect(jsonPath("$.[*].status").value(hasItem(DEFAULT_STATUS)))
            .andExpect(jsonPath("$.[*].userId").value(hasItem(DEFAULT_USER_ID.intValue())))
            .andExpect(jsonPath("$.[*].createTime").value(hasItem(DEFAULT_CREATE_TIME.toString())))
            .andExpect(jsonPath("$.[*].updateTime").value(hasItem(DEFAULT_UPDATE_TIME.toString())))
            .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString())));
    }
    
    @Test
    @Transactional
    public void getMyJob() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get the myJob
        restMyJobMockMvc.perform(get("/api/my-jobs/{id}", myJob.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(myJob.getId().intValue()))
            .andExpect(jsonPath("$.name").value(DEFAULT_NAME))
            .andExpect(jsonPath("$.instanceId").value(DEFAULT_INSTANCE_ID))
            .andExpect(jsonPath("$.status").value(DEFAULT_STATUS))
            .andExpect(jsonPath("$.userId").value(DEFAULT_USER_ID.intValue()))
            .andExpect(jsonPath("$.createTime").value(DEFAULT_CREATE_TIME.toString()))
            .andExpect(jsonPath("$.updateTime").value(DEFAULT_UPDATE_TIME.toString()))
            .andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION.toString()));
    }


    @Test
    @Transactional
    public void getMyJobsByIdFiltering() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        Long id = myJob.getId();

        defaultMyJobShouldBeFound("id.equals=" + id);
        defaultMyJobShouldNotBeFound("id.notEquals=" + id);

        defaultMyJobShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultMyJobShouldNotBeFound("id.greaterThan=" + id);

        defaultMyJobShouldBeFound("id.lessThanOrEqual=" + id);
        defaultMyJobShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllMyJobsByNameIsEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where name equals to DEFAULT_NAME
        defaultMyJobShouldBeFound("name.equals=" + DEFAULT_NAME);

        // Get all the myJobList where name equals to UPDATED_NAME
        defaultMyJobShouldNotBeFound("name.equals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllMyJobsByNameIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where name not equals to DEFAULT_NAME
        defaultMyJobShouldNotBeFound("name.notEquals=" + DEFAULT_NAME);

        // Get all the myJobList where name not equals to UPDATED_NAME
        defaultMyJobShouldBeFound("name.notEquals=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllMyJobsByNameIsInShouldWork() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where name in DEFAULT_NAME or UPDATED_NAME
        defaultMyJobShouldBeFound("name.in=" + DEFAULT_NAME + "," + UPDATED_NAME);

        // Get all the myJobList where name equals to UPDATED_NAME
        defaultMyJobShouldNotBeFound("name.in=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllMyJobsByNameIsNullOrNotNull() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where name is not null
        defaultMyJobShouldBeFound("name.specified=true");

        // Get all the myJobList where name is null
        defaultMyJobShouldNotBeFound("name.specified=false");
    }
                @Test
    @Transactional
    public void getAllMyJobsByNameContainsSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where name contains DEFAULT_NAME
        defaultMyJobShouldBeFound("name.contains=" + DEFAULT_NAME);

        // Get all the myJobList where name contains UPDATED_NAME
        defaultMyJobShouldNotBeFound("name.contains=" + UPDATED_NAME);
    }

    @Test
    @Transactional
    public void getAllMyJobsByNameNotContainsSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where name does not contain DEFAULT_NAME
        defaultMyJobShouldNotBeFound("name.doesNotContain=" + DEFAULT_NAME);

        // Get all the myJobList where name does not contain UPDATED_NAME
        defaultMyJobShouldBeFound("name.doesNotContain=" + UPDATED_NAME);
    }


    @Test
    @Transactional
    public void getAllMyJobsByInstanceIdIsEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where instanceId equals to DEFAULT_INSTANCE_ID
        defaultMyJobShouldBeFound("instanceId.equals=" + DEFAULT_INSTANCE_ID);

        // Get all the myJobList where instanceId equals to UPDATED_INSTANCE_ID
        defaultMyJobShouldNotBeFound("instanceId.equals=" + UPDATED_INSTANCE_ID);
    }

    @Test
    @Transactional
    public void getAllMyJobsByInstanceIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where instanceId not equals to DEFAULT_INSTANCE_ID
        defaultMyJobShouldNotBeFound("instanceId.notEquals=" + DEFAULT_INSTANCE_ID);

        // Get all the myJobList where instanceId not equals to UPDATED_INSTANCE_ID
        defaultMyJobShouldBeFound("instanceId.notEquals=" + UPDATED_INSTANCE_ID);
    }

    @Test
    @Transactional
    public void getAllMyJobsByInstanceIdIsInShouldWork() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where instanceId in DEFAULT_INSTANCE_ID or UPDATED_INSTANCE_ID
        defaultMyJobShouldBeFound("instanceId.in=" + DEFAULT_INSTANCE_ID + "," + UPDATED_INSTANCE_ID);

        // Get all the myJobList where instanceId equals to UPDATED_INSTANCE_ID
        defaultMyJobShouldNotBeFound("instanceId.in=" + UPDATED_INSTANCE_ID);
    }

    @Test
    @Transactional
    public void getAllMyJobsByInstanceIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where instanceId is not null
        defaultMyJobShouldBeFound("instanceId.specified=true");

        // Get all the myJobList where instanceId is null
        defaultMyJobShouldNotBeFound("instanceId.specified=false");
    }
                @Test
    @Transactional
    public void getAllMyJobsByInstanceIdContainsSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where instanceId contains DEFAULT_INSTANCE_ID
        defaultMyJobShouldBeFound("instanceId.contains=" + DEFAULT_INSTANCE_ID);

        // Get all the myJobList where instanceId contains UPDATED_INSTANCE_ID
        defaultMyJobShouldNotBeFound("instanceId.contains=" + UPDATED_INSTANCE_ID);
    }

    @Test
    @Transactional
    public void getAllMyJobsByInstanceIdNotContainsSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where instanceId does not contain DEFAULT_INSTANCE_ID
        defaultMyJobShouldNotBeFound("instanceId.doesNotContain=" + DEFAULT_INSTANCE_ID);

        // Get all the myJobList where instanceId does not contain UPDATED_INSTANCE_ID
        defaultMyJobShouldBeFound("instanceId.doesNotContain=" + UPDATED_INSTANCE_ID);
    }


    @Test
    @Transactional
    public void getAllMyJobsByStatusIsEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where status equals to DEFAULT_STATUS
        defaultMyJobShouldBeFound("status.equals=" + DEFAULT_STATUS);

        // Get all the myJobList where status equals to UPDATED_STATUS
        defaultMyJobShouldNotBeFound("status.equals=" + UPDATED_STATUS);
    }

    @Test
    @Transactional
    public void getAllMyJobsByStatusIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where status not equals to DEFAULT_STATUS
        defaultMyJobShouldNotBeFound("status.notEquals=" + DEFAULT_STATUS);

        // Get all the myJobList where status not equals to UPDATED_STATUS
        defaultMyJobShouldBeFound("status.notEquals=" + UPDATED_STATUS);
    }

    @Test
    @Transactional
    public void getAllMyJobsByStatusIsInShouldWork() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where status in DEFAULT_STATUS or UPDATED_STATUS
        defaultMyJobShouldBeFound("status.in=" + DEFAULT_STATUS + "," + UPDATED_STATUS);

        // Get all the myJobList where status equals to UPDATED_STATUS
        defaultMyJobShouldNotBeFound("status.in=" + UPDATED_STATUS);
    }

    @Test
    @Transactional
    public void getAllMyJobsByStatusIsNullOrNotNull() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where status is not null
        defaultMyJobShouldBeFound("status.specified=true");

        // Get all the myJobList where status is null
        defaultMyJobShouldNotBeFound("status.specified=false");
    }

    @Test
    @Transactional
    public void getAllMyJobsByStatusIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where status is greater than or equal to DEFAULT_STATUS
        defaultMyJobShouldBeFound("status.greaterThanOrEqual=" + DEFAULT_STATUS);

        // Get all the myJobList where status is greater than or equal to UPDATED_STATUS
        defaultMyJobShouldNotBeFound("status.greaterThanOrEqual=" + UPDATED_STATUS);
    }

    @Test
    @Transactional
    public void getAllMyJobsByStatusIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where status is less than or equal to DEFAULT_STATUS
        defaultMyJobShouldBeFound("status.lessThanOrEqual=" + DEFAULT_STATUS);

        // Get all the myJobList where status is less than or equal to SMALLER_STATUS
        defaultMyJobShouldNotBeFound("status.lessThanOrEqual=" + SMALLER_STATUS);
    }

    @Test
    @Transactional
    public void getAllMyJobsByStatusIsLessThanSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where status is less than DEFAULT_STATUS
        defaultMyJobShouldNotBeFound("status.lessThan=" + DEFAULT_STATUS);

        // Get all the myJobList where status is less than UPDATED_STATUS
        defaultMyJobShouldBeFound("status.lessThan=" + UPDATED_STATUS);
    }

    @Test
    @Transactional
    public void getAllMyJobsByStatusIsGreaterThanSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where status is greater than DEFAULT_STATUS
        defaultMyJobShouldNotBeFound("status.greaterThan=" + DEFAULT_STATUS);

        // Get all the myJobList where status is greater than SMALLER_STATUS
        defaultMyJobShouldBeFound("status.greaterThan=" + SMALLER_STATUS);
    }


    @Test
    @Transactional
    public void getAllMyJobsByUserIdIsEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where userId equals to DEFAULT_USER_ID
        defaultMyJobShouldBeFound("userId.equals=" + DEFAULT_USER_ID);

        // Get all the myJobList where userId equals to UPDATED_USER_ID
        defaultMyJobShouldNotBeFound("userId.equals=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyJobsByUserIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where userId not equals to DEFAULT_USER_ID
        defaultMyJobShouldNotBeFound("userId.notEquals=" + DEFAULT_USER_ID);

        // Get all the myJobList where userId not equals to UPDATED_USER_ID
        defaultMyJobShouldBeFound("userId.notEquals=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyJobsByUserIdIsInShouldWork() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where userId in DEFAULT_USER_ID or UPDATED_USER_ID
        defaultMyJobShouldBeFound("userId.in=" + DEFAULT_USER_ID + "," + UPDATED_USER_ID);

        // Get all the myJobList where userId equals to UPDATED_USER_ID
        defaultMyJobShouldNotBeFound("userId.in=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyJobsByUserIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where userId is not null
        defaultMyJobShouldBeFound("userId.specified=true");

        // Get all the myJobList where userId is null
        defaultMyJobShouldNotBeFound("userId.specified=false");
    }

    @Test
    @Transactional
    public void getAllMyJobsByUserIdIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where userId is greater than or equal to DEFAULT_USER_ID
        defaultMyJobShouldBeFound("userId.greaterThanOrEqual=" + DEFAULT_USER_ID);

        // Get all the myJobList where userId is greater than or equal to UPDATED_USER_ID
        defaultMyJobShouldNotBeFound("userId.greaterThanOrEqual=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyJobsByUserIdIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where userId is less than or equal to DEFAULT_USER_ID
        defaultMyJobShouldBeFound("userId.lessThanOrEqual=" + DEFAULT_USER_ID);

        // Get all the myJobList where userId is less than or equal to SMALLER_USER_ID
        defaultMyJobShouldNotBeFound("userId.lessThanOrEqual=" + SMALLER_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyJobsByUserIdIsLessThanSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where userId is less than DEFAULT_USER_ID
        defaultMyJobShouldNotBeFound("userId.lessThan=" + DEFAULT_USER_ID);

        // Get all the myJobList where userId is less than UPDATED_USER_ID
        defaultMyJobShouldBeFound("userId.lessThan=" + UPDATED_USER_ID);
    }

    @Test
    @Transactional
    public void getAllMyJobsByUserIdIsGreaterThanSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where userId is greater than DEFAULT_USER_ID
        defaultMyJobShouldNotBeFound("userId.greaterThan=" + DEFAULT_USER_ID);

        // Get all the myJobList where userId is greater than SMALLER_USER_ID
        defaultMyJobShouldBeFound("userId.greaterThan=" + SMALLER_USER_ID);
    }


    @Test
    @Transactional
    public void getAllMyJobsByCreateTimeIsEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where createTime equals to DEFAULT_CREATE_TIME
        defaultMyJobShouldBeFound("createTime.equals=" + DEFAULT_CREATE_TIME);

        // Get all the myJobList where createTime equals to UPDATED_CREATE_TIME
        defaultMyJobShouldNotBeFound("createTime.equals=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllMyJobsByCreateTimeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where createTime not equals to DEFAULT_CREATE_TIME
        defaultMyJobShouldNotBeFound("createTime.notEquals=" + DEFAULT_CREATE_TIME);

        // Get all the myJobList where createTime not equals to UPDATED_CREATE_TIME
        defaultMyJobShouldBeFound("createTime.notEquals=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllMyJobsByCreateTimeIsInShouldWork() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where createTime in DEFAULT_CREATE_TIME or UPDATED_CREATE_TIME
        defaultMyJobShouldBeFound("createTime.in=" + DEFAULT_CREATE_TIME + "," + UPDATED_CREATE_TIME);

        // Get all the myJobList where createTime equals to UPDATED_CREATE_TIME
        defaultMyJobShouldNotBeFound("createTime.in=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllMyJobsByCreateTimeIsNullOrNotNull() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where createTime is not null
        defaultMyJobShouldBeFound("createTime.specified=true");

        // Get all the myJobList where createTime is null
        defaultMyJobShouldNotBeFound("createTime.specified=false");
    }

    @Test
    @Transactional
    public void getAllMyJobsByUpdateTimeIsEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where updateTime equals to DEFAULT_UPDATE_TIME
        defaultMyJobShouldBeFound("updateTime.equals=" + DEFAULT_UPDATE_TIME);

        // Get all the myJobList where updateTime equals to UPDATED_UPDATE_TIME
        defaultMyJobShouldNotBeFound("updateTime.equals=" + UPDATED_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void getAllMyJobsByUpdateTimeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where updateTime not equals to DEFAULT_UPDATE_TIME
        defaultMyJobShouldNotBeFound("updateTime.notEquals=" + DEFAULT_UPDATE_TIME);

        // Get all the myJobList where updateTime not equals to UPDATED_UPDATE_TIME
        defaultMyJobShouldBeFound("updateTime.notEquals=" + UPDATED_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void getAllMyJobsByUpdateTimeIsInShouldWork() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where updateTime in DEFAULT_UPDATE_TIME or UPDATED_UPDATE_TIME
        defaultMyJobShouldBeFound("updateTime.in=" + DEFAULT_UPDATE_TIME + "," + UPDATED_UPDATE_TIME);

        // Get all the myJobList where updateTime equals to UPDATED_UPDATE_TIME
        defaultMyJobShouldNotBeFound("updateTime.in=" + UPDATED_UPDATE_TIME);
    }

    @Test
    @Transactional
    public void getAllMyJobsByUpdateTimeIsNullOrNotNull() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        // Get all the myJobList where updateTime is not null
        defaultMyJobShouldBeFound("updateTime.specified=true");

        // Get all the myJobList where updateTime is null
        defaultMyJobShouldNotBeFound("updateTime.specified=false");
    }
    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultMyJobShouldBeFound(String filter) throws Exception {
        restMyJobMockMvc.perform(get("/api/my-jobs?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(myJob.getId().intValue())))
            .andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
            .andExpect(jsonPath("$.[*].instanceId").value(hasItem(DEFAULT_INSTANCE_ID)))
            .andExpect(jsonPath("$.[*].status").value(hasItem(DEFAULT_STATUS)))
            .andExpect(jsonPath("$.[*].userId").value(hasItem(DEFAULT_USER_ID.intValue())))
            .andExpect(jsonPath("$.[*].createTime").value(hasItem(DEFAULT_CREATE_TIME.toString())))
            .andExpect(jsonPath("$.[*].updateTime").value(hasItem(DEFAULT_UPDATE_TIME.toString())))
            .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString())));

        // Check, that the count call also returns 1
        restMyJobMockMvc.perform(get("/api/my-jobs/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultMyJobShouldNotBeFound(String filter) throws Exception {
        restMyJobMockMvc.perform(get("/api/my-jobs?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restMyJobMockMvc.perform(get("/api/my-jobs/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingMyJob() throws Exception {
        // Get the myJob
        restMyJobMockMvc.perform(get("/api/my-jobs/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateMyJob() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        int databaseSizeBeforeUpdate = myJobRepository.findAll().size();

        // Update the myJob
        MyJob updatedMyJob = myJobRepository.findById(myJob.getId()).get();
        // Disconnect from session so that the updates on updatedMyJob are not directly saved in db
        em.detach(updatedMyJob);
        updatedMyJob
            .name(UPDATED_NAME)
            .instanceId(UPDATED_INSTANCE_ID)
            .status(UPDATED_STATUS)
            .userId(UPDATED_USER_ID)
            .createTime(UPDATED_CREATE_TIME)
            .updateTime(UPDATED_UPDATE_TIME)
            .description(UPDATED_DESCRIPTION);
        MyJobDTO myJobDTO = myJobMapper.toDto(updatedMyJob);

        restMyJobMockMvc.perform(put("/api/my-jobs").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myJobDTO)))
            .andExpect(status().isOk());

        // Validate the MyJob in the database
        List<MyJob> myJobList = myJobRepository.findAll();
        assertThat(myJobList).hasSize(databaseSizeBeforeUpdate);
        MyJob testMyJob = myJobList.get(myJobList.size() - 1);
        assertThat(testMyJob.getName()).isEqualTo(UPDATED_NAME);
        assertThat(testMyJob.getInstanceId()).isEqualTo(UPDATED_INSTANCE_ID);
        assertThat(testMyJob.getStatus()).isEqualTo(UPDATED_STATUS);
        assertThat(testMyJob.getUserId()).isEqualTo(UPDATED_USER_ID);
        assertThat(testMyJob.getCreateTime()).isEqualTo(UPDATED_CREATE_TIME);
        assertThat(testMyJob.getUpdateTime()).isEqualTo(UPDATED_UPDATE_TIME);
        assertThat(testMyJob.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
    }

    @Test
    @Transactional
    public void updateNonExistingMyJob() throws Exception {
        int databaseSizeBeforeUpdate = myJobRepository.findAll().size();

        // Create the MyJob
        MyJobDTO myJobDTO = myJobMapper.toDto(myJob);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restMyJobMockMvc.perform(put("/api/my-jobs").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(myJobDTO)))
            .andExpect(status().isBadRequest());

        // Validate the MyJob in the database
        List<MyJob> myJobList = myJobRepository.findAll();
        assertThat(myJobList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteMyJob() throws Exception {
        // Initialize the database
        myJobRepository.saveAndFlush(myJob);

        int databaseSizeBeforeDelete = myJobRepository.findAll().size();

        // Delete the myJob
        restMyJobMockMvc.perform(delete("/api/my-jobs/{id}", myJob.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<MyJob> myJobList = myJobRepository.findAll();
        assertThat(myJobList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
